import { configureStore, ThunkAction, Action } from "@reduxjs/toolkit";
import userReducer from "./slice/user";
import appReducer from "./slice/app";
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import sysConfigReducer from "./slice/sysConfig";
import SysDictReducer from "./slice/SysDict";
import SysMenusReducer from "./slice/sysMenus";

// 类型定义
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
export type AppThunk<ReturnType = void> = ThunkAction<
  ReturnType,
  RootState,
  unknown,
  Action<string>
>;

export const store = configureStore({
  reducer: {
    app: appReducer,
    user: userReducer,
    sysConfig: sysConfigReducer,
    sysDict: SysDictReducer,
    sysMenus: SysMenusReducer,
  },
});

// 只是加上了类型定义
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
